<?php
	class GP_page_view extends GP_controleur
	{
		var $controleur;
		var $table;
		var $action_form;
		
		function __construct()
		{
			global $page;
			$this -> controleur = parent::getInstance($page);
		}
		
		function form()
		{
			include_once(DIR_SCRIPTS . 'view_' . $this -> table . '.php');
		}
		
		function afficher()
		{			
			global $page, $urirw;
			if (strlen($urirw))
			{
				$pagerw = fakeurl($urirw);
				$htmltmp = $this -> controleur -> htmlrw('header');
				$htmltmp .= $this -> controleur -> htmlrw($page);
				$htmltmp .= $this -> controleur -> htmlrw('footer');
				savefile($pagerw, $htmltmp);
				if (!IS_IE)
					header("HTTP/1.1 301 Moved Permanently");
				include($urirw);
			}
			else
			{
				$this -> controleur -> add_html('header');
				$this -> controleur -> add_html($page);
				$this -> controleur -> add_html('footer');
			}
		}
		
		function setvar($var, $val)
		{
			global $urirw;
			if (strlen($urirw))
				$this -> $var = $val;
			else
				$this -> controleur -> $var = $val;
		}
	}
	$gp_fonc = GP_fonctions::getInstance();
	$gp_db = GP_db::getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
	$gp_request = GP_secure::getInstance();
	
	$page_view = new GP_page_view;
	$erreur_table = false;
	$erreur_cle = false;
	$table = $gp_request -> Get('table', $GLOBALS["table"]);
	$cle = $gp_request -> Get('cle', $GLOBALS["cle"]);
	$id = $gp_request -> Get('id', $GLOBALS["id"]);
	
	if ($cle <> md5('view' . get_s("bo_user") . date('dmY') . $table . $id))
		$erreur_cle = true;
	
	if (!$erreur_cle)
	{
		if (!strlen($table) || !strlen($id) || !is_file(DIR_SCRIPTS . 'view_' . $table . '.php'))
			$erreur_table = true;
		else
		{
			$page_view -> table = $table;
			$page_view -> id = $id;
			$page_view -> form();
		}
	}
	
	$page_view -> setvar('erreur_cle', $erreur_cle);
	$page_view -> setvar('erreur_table', $erreur_table);
	$page_view -> setvar('table', $table);
	$page_view -> setvar('id', $id);
	$page_view -> setvar('page', $GLOBALS["page"]);
	$page_view -> afficher();
?>